var __extends =
    (this && this.__extends) ||
    (function () {
      var e = function (t, o) {
        return (e =
          Object.setPrototypeOf ||
          ({ __proto__: [] } instanceof Array &&
            function (e, t) {
              e.__proto__ = t;
            }) ||
          function (e, t) {
            for (var o in t)
              Object.prototype.hasOwnProperty.call(t, o) && (e[o] = t[o]);
          })(t, o);
      };
      return function (t, o) {
        function n() {
          this.constructor = t;
        }
        if ("function" != typeof o && null !== o)
          throw new TypeError(
            "Class extends value " + String(o) + " is not a constructor or null"
          );
        e(t, o),
          (t.prototype =
            null === o
              ? Object.create(o)
              : ((n.prototype = o.prototype), new n()));
      };
    })(),
  Browser = Laya.Browser,
  LoginView = (function (e) {
    function t() {
      var t = e.call(this) || this;
      return (
        t.getWxOpenid(),
        t.getSpread(),
        t.btn_login_start_game.on(Laya.Event.CLICK, null, t.onStartGamefn),
        t
      );
    }
    return (
      __extends(t, e),
      (t.prototype.onStartGamefn = function () {
        Browser.window, Browser.document;
        if (Browser.window.BSL)
          try {
            Browser.window.BSL.KeepBright("1");
          } catch (e) {}
        else
          (Browser.document.noSleep = new NoSleep()),
            Browser.document.addEventListener(
              "click",
              function e() {
                document.removeEventListener("click", e, !1),
                  this.noSleep.enable();
              },
              !1
            );
        var e = laya.net.LocalStorage.getItem("accessToken"),
          t = laya.net.LocalStorage.getItem("loginTime");
        if (e && t) {
          if (Date.now() - Number(t) < 864e5) {
            var o = ServerListView.openServerListView();
            return Laya.stage.addChild(o), void this.removeSelf();
          }
        }
        RegDialog.showLoginAndRegView();
      }),
      (t.prototype.getQueryString = function (e) {
        var t = new RegExp("(^|&)" + e + "=([^&]*)(&|$)", "i"),
          o = Browser.window.location.search.substr(1).match(t);
        return null != o ? Browser.window.unescape(o[2]) : null;
      }),
      (t.prototype.getWxOpenid = function () {
        this.wxCode = null;
        var e = this.getQueryString("code");
        if (null != e && "" != e) {
          if (laya.net.LocalStorage.getItem("wxCode") != e) {
            (this.wxCode = e), laya.net.LocalStorage.getItem("openid");
            var t = new Ajax(this);
            (t.success = this.openidSuccess),
              t.get(
                Environment.apiHost + "/user-service/user/weixinAuth?code=" + e
              );
          }
        }
      }),
      (t.prototype.getSpread = function () {
        var e = this.getQueryString("c");
        e && laya.net.LocalStorage.setItem("code", e);
        var t = this.getQueryString("ch");
        t && laya.net.LocalStorage.setItem("channel", t);
      }),
      (t.prototype.openidSuccess = function (e) {
        0 == e.code
          ? (laya.net.LocalStorage.setItem("openid", e.data),
            this.wxCode && laya.net.LocalStorage.setItem("wxCode", this.wxCode))
          : ToastView.toastView(e.msg);
      }),
      t
    );
  })(ui.LoginViewUI);
